import 'package:app_health/constant/Constans.dart';
import 'package:app_health/utils/ImageUtils.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';

class MeWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return MeStateWidget();
  }

  static startMePage(BuildContext c) {
    Navigator.push(c, MaterialPageRoute(builder: (context) => new MeWidget()));
  }
}

class MeStateWidget extends State<MeWidget> {

  String _userName = "KANGGUIYANG";
  var _age = 18;
  var _height = 180;
  var _weight = 80;
  var _sex = '男';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        elevation: 0,
        backgroundColor: Color(0xFF0AD0B2),
        actions: <Widget>[
          IconButton(
              icon: Icon(
                Icons.settings,
                color: Colors.white,
              ),
              onPressed: null)
        ],
        leading: Container(),
        // 群的开发提供的意见
        title: Text("我的"),
      ),
      body: homeWidget(),
    );
  }

  /// 主要布局
  Widget homeWidget() {
    return Column(
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Container(
          child: Stack(
            children: <Widget>[
              Container(
                height: 55.0,
                color: Color(Constants.MAIN_COLOR),
              ),
              Container(
                height: 85.0,
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(15.0))),
                margin: EdgeInsets.all(15.0),
                child: userInfoWidget(),
              ),
            ],
          ),
        ),
        // 年龄 身高  体重 性别
        Container(
          decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(15.0))),
          margin: EdgeInsets.only(left: 15.0, right: 15.0, bottom: 15.0),
          child: Column(
            children: <Widget>[ageList(), height(), weight(), sex()],
          ),
        ),
        Container(
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(15.0))),
            margin: EdgeInsets.only(left: 15.0, right: 15.0, bottom: 15.0),
            child: healthOrder())
      ],
    );
  }

  /// 年龄
  ListTile ageList() {
    return ListTile(
      leading: Image.asset(ImageUtils.getImagePath("icon_age")),
      title: Text("年龄"),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text(
            "$_age岁",
            style: TextStyle(fontSize: 12.0, color: Colors.grey),
          ),
          Icon(Icons.chevron_right)
        ],
      ),
    );
  }

  /// 身高
  ListTile height() {
    return ListTile(
      leading: Image.asset(ImageUtils.getImagePath("icon_height")),
      title: Text("身高"),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text(
            "$_height厘米",
            style: TextStyle(fontSize: 12.0, color: Colors.grey),
          ),
          Icon(Icons.chevron_right)
        ],
      ),
    );
  }

  /// 体重
  ListTile weight() {
    return ListTile(
      leading:  Image.asset(ImageUtils.getImagePath("icon_weight")),
      title: Text("体重"),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text(
            "$_weight公斤",
            style: TextStyle(fontSize: 12.0, color: Colors.grey),
          ),
          Icon(Icons.chevron_right)
        ],
      ),
    );
  }

  /// 性别
  ListTile sex() {
    return ListTile(
      leading:  Image.asset(ImageUtils.getImagePath("icon_sex")),
      title: Text("性别"),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text(
            "$_sex",
            style: TextStyle(fontSize: 12.0, color: Colors.grey),
          ),
          Icon(Icons.chevron_right)
        ],
      ),
    );
  }

  /// 健康记录
  ListTile healthOrder() {
    return ListTile(
      leading:  Image.asset(ImageUtils.getImagePath("icon_health")),
      title: Text("健康记录"),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[Icon(Icons.chevron_right)],
      ),
    );
  }

  /// 头部框内个人信息 头像 名称 号码 点击事件TODO
  Widget userInfoWidget() {
    return Row(
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(left: 15.0, right: 15.0),
          child: Image(
            image: NetworkImage(
                "http://img5.duitang.com/uploads/item/201409/23/20140923094045_BNYji.thumb.700_0.png"),
            width: 55.0,
          ),
        ),
        // 姓名和电话号码
        Expanded(
          child: Column(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Row(
                children: <Widget>[
                  Text(_userName),
                 Image.asset(ImageUtils.getImagePath("icon_top_sex"))
                ],
              ),
              Container(
                margin: EdgeInsets.only(top: 10.0),
                child: Text("18252032703"),
              )
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(right: 5.0),
          alignment: Alignment.centerRight,
          child: IconButton(icon: Icon(Icons.chevron_right), onPressed: null),
        )
      ],
    );
  }
}
